import { API } from "@/services";
import { defineStore } from "pinia";
import { ref } from "vue";
import { useTokenStore } from "../token";

export interface Notifycation {
  title: string;
  content: string;
}

export const useNotifycationStore = defineStore("notifycation", () => {
  const notifycationlist = ref<Notifycation[]>();

  async function dispatchGetNotifycation() {
    const tokenStore = useTokenStore();
    await API.users.getNotifycation(tokenStore.token.role, tokenStore.token.id).then((res) => {
      notifycationlist.value = res.data.notices.map((item:{I_id:number, information: { content:string } } )=>{
        return {
          title: `通知${item.I_id}`,
          content: item.information.content,
        }
      })
      console.log(notifycationlist.value);
    })
  }

  return {
    notifycationlist,
    dispatchGetNotifycation,
  }
});
